package com.iqik.rmi.main;

import com.iqik.rmi.intfs.IHelloService;
import com.iqik.rmi.intfs_impl.HelloServiceImpl;

import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;

public class RMIServer {

    /***
     * **使用rmi时候必须要保持客户端与服务端的命名完全一致，而且两端实体类都需要序列化**
     */

    public static void main(String[] args) throws RemoteException, AlreadyBoundException, MalformedURLException {
        // 1、创建HelloService实例
        IHelloService service = new HelloServiceImpl();

        // 2、获取注册表
        LocateRegistry.createRegistry(8100);
        // 3、对象绑定
        // bind方法参数：
        //    arg1: rmi://ip:port/server_name
        //    arg2: 绑定对象
        Naming.bind("//127.0.0.1:8100/sayHello", service);
    }
}
